import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/http/api/api.dart';

class CommunityPageController extends GetxController
    with GetTickerProviderStateMixin {
  late TabController tabController;

  RxList<Tab> tabs = <Tab>[const Tab(text: "全部")].obs;
  List<String> categoryIds = ["00000"];

  @override
  void onInit() {
    tabController = TabController(length: tabs.length, vsync: this);
    super.onInit();
  }

  @override
  onReady() {
    getCategoryData();
  }

  ///获取分类
  getCategoryData() async {
    Api.getCommunityClassificationLists(isAll: false).then((response) {
      if (response.isNotEmpty) {
        for (var item in response) {
          categoryIds.add(item.id ?? "");
          tabs.add(Tab(text: item.name));
        }
        tabController = TabController(length: tabs.length, vsync: this);
        update();
      }
    });
  }
}
